package com.itheima.day14.ZuoYe.ZuoYe2;

import java.util.*;
import java.util.stream.Collectors;

public class Test {
    public static void main(String[] args) {
        // 创建10个Stu对象
        List<Stu> students = generateRandomStudents(10);
        List<Stu> students2 = generateRandomStudents(10);
        List<Stu> students3 = generateRandomStudents(10);
        Map<String, List<Stu>> map = new HashMap<>();
        List<Stu> stu = students.stream().sorted((o1, o2) -> Integer.compare(o1.getAge(), o2.getAge())).collect(Collectors.toList());
        List<Stu> stu2 = students2.stream().sorted((o1, o2) -> Integer.compare(o1.getAge(), o2.getAge())).collect(Collectors.toList());
        List<Stu> stu3 = students3.stream().sorted((o1, o2) -> Integer.compare(o1.getAge(), o2.getAge())).collect(Collectors.toList());
        map.put("一年级1班", stu);
        map.put("二年级2班", stu2);
        map.put("三年级3班", stu3);
        map.forEach((k, v) -> {
            System.out.println(k + ": " + v);
        });
        }
    public static List<Stu> generateRandomStudents(int count) {
        List<Stu> students = new ArrayList<>();

        // 准备一些随机数据
        String[] firstNames = {"张", "李", "王", "刘", "陈", "杨", "赵", "黄", "周", "吴",
                "徐", "孙", "胡", "朱", "高", "林", "何", "郭", "马", "罗"};
        String[] lastNames = {"伟", "芳", "娜", "敏", "静", "丽", "强", "磊", "军", "洋",
                "勇", "艳", "杰", "娟", "涛", "明", "超", "秀英", "霞", "平"};

        Random random = new Random();

        for (int i = 1; i <= count; i++) {
            // 生成随机学号 (STU001 - STU030)
            String id = String.format("STU%03d", i);

            // 随机生成姓名
            String firstName = firstNames[random.nextInt(firstNames.length)];
            String lastName = lastNames[random.nextInt(lastNames.length)];
            String name = firstName + lastName;

            // 随机生成年龄 (18-25岁)
            int age = 18 + random.nextInt(8);

            // 创建Stu对象
            Stu student = new Stu(id, name, age);
            students.add(student);
        }

        return students;
    }
    }

